package com.pi.smart.wxmini.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.pi.base.dto.result.AppResult;
import com.pi.dc.service.DcBedService;
import com.pi.dc.service.DcDeviceInfoService;
import com.pi.dc.vo.UserBedInfoVo;
import com.pi.dc.vo.UserBedSketch;
import com.pi.http.base.controller.BaseController;


@RequestMapping("/smart/bed")
@RestController
public class SmartDeviceController extends BaseController{

  @Autowired
  private DcBedService bedService;
  
  @Autowired
  private DcDeviceInfoService deviceInfoService;
  
  
  @RequestMapping("/bind")
  public AppResult bind(String deviceCode, Long sourceId){
    Long bedId = bedService.addBedInfo(deviceCode, sourceId, getLoginUserId());
    return AppResult.newSuccessResult(bedId);
  }
  
  @RequestMapping("/wifi")
  public AppResult wifi(Long deviceId, String wifiSsid, String wifiPass){
    bedService.addBedWifi(getLoginUserId(), deviceId, wifiSsid, wifiPass);
    return AppResult.OK;
  }
  
  @RequestMapping("/devname")
  public AppResult updateName(Long deviceId, String deviceName){
    deviceInfoService.updateDeviceName(getLoginUserId(), deviceId, deviceName);
    return AppResult.OK;
  }
  
  @RequestMapping("/userbedinfo")
  public AppResult queryBedInfo(Long shareId){
    UserBedSketch sketch = bedService.queryUserBedVoWithShare(getLoginUserId(), shareId);
    return AppResult.newSuccessResult(sketch);
  }
  
  @RequestMapping("/userbedlist")
  public AppResult queryBedList(){
    List<UserBedInfoVo> list = bedService.queryUserBedInfoVo(getLoginUserId());
    return AppResult.newSuccessResult(list);
  }
  
  @RequestMapping("/remove")
  public AppResult removeBedInfo(Long bedId) {
    bedService.delBedInfo(bedId, getLoginUserId());
    return AppResult.newSuccessResult(null);
  }
}
